
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <iostream>

using namespace testing;
class nativeUnit
{
public:
	int Gen(int a,void* p )
	{
		std::cout<<"_nativeRun_run____________"<<a<<std::endl;
		return a;
	}
	int Gen(void)
	{
		std::cout<<"native _run_gen_void_version"<<std::endl;
		return -1;
	}
};

void gCheck()
{
	static int count = 0;
	std::cout<<"______Check _run_______"<<count++<<" Times___\n";
}


class MockUnit :public nativeUnit
{
public:
	
	MOCK_METHOD2(Gen,int(int,void*));
	MOCK_METHOD0(Gen,int());
	MockUnit()
	{
		ON_CALL(*this,Gen())
			.WillByDefault(Invoke(this, &MockUnit::parentGen2));
		ON_CALL(*this,Gen(An<int>(),An<void*>()))
			.WillByDefault(Invoke(this,&MockUnit::parentGen));

	}

	int parentGen2()
	{
		return nativeUnit::Gen();
	}
	int parentGen(int a,void * p)
	{
		return nativeUnit::Gen(a,p);
	}
	
private:
	nativeUnit m_Real;

};

class TestBeahev : public testing::Test
{
public:
};
TEST_F(TestBeahev,1)
{
	std::vector<MockUnit*> lpVec;
	for(int i = 0;i<10;++i)
	{
		
		MockUnit* lpnst = new MockUnit;
		lpVec.push_back(lpnst);
		EXPECT_CALL(*lpnst,Gen(_,_))
			.Times(1)
			.WillOnce(DoAll(
			InvokeWithoutArgs(gCheck)
			,Invoke(lpnst,&MockUnit::parentGen)
			)
			);
	}

	for(int i = 0;i<10;++i)
	{
		lpVec[i]->Gen(i,NULL);
	}

}